package priv.yiyuan.example.composite.ticket;

/**
 * 责任链模式 - 一线支持人员
 *
 * @author YiYuan
 * @data 2025/8/29
 * @apoNote
 */
public class FirstLineSupport implements TicketHandler {

    private String name;

    private TicketHandler nextHandler;

    public FirstLineSupport(String name) {
        this.name = name;
    }

    @Override
    public void setNextHandler(TicketHandler nextHandler) {
        this.nextHandler = nextHandler;
    }

    @Override
    public boolean handleTicket(TicketComponent ticket) {

        if (canHandle(ticket)) {
            System.out.println("一线支持人员 " + name + " 正在处理工单: " + ticket.description);
            ticket.updateStatus(TicketStatus.COMPLETED);
            return true;
        }
        else if (nextHandler != null) {
            System.out.println("一线支持人员 " + name + " 无法处理, 转交二线支持");
            return nextHandler.handleTicket(ticket);
        }

        return false;
    }

    private boolean canHandle(TicketComponent ticket) {
        return ticket instanceof SimpleTicket && !ticket.description.contains("服务器") && !ticket.description.contains("网络");
    }

}
